import java.io.*;

public class Input {
    private BufferedReader reader;
    private String filePath;

    // read from txt file or input
    public Input(String dungeonName) {
        try {
            if (dungeonName == null) reader = new BufferedReader(new InputStreamReader(System.in));
            else {
                filePath = "src" + File.separator + "Dungeons" + File.separator + dungeonName;
                if (!filePath.endsWith(".txt")) filePath += ".txt";
                reader = new BufferedReader(new FileReader(filePath));
            }
        } catch (IOException e) {
            System.out.println("Failed initializing Input: " + e);
        }
    }

    public int readInt() {
        try {
            return Integer.parseInt(reader.readLine().trim());
        } catch (IOException e) {
            System.out.println("Failed reading int: " + e);
            return -1;
        }
    }

    public char readChar() {
        try {
            return reader.readLine().trim().toLowerCase().charAt(0);
        } catch (IOException e) {
            System.out.println("Failed reading char: " + e);
            return '/';
        }
    }

    public String readLine() {
        try {
            return reader.readLine();
        } catch (IOException e) {
            System.out.println("Failed reading line: " + e);
            return null;
        }
    }

    public void close() {
        try {
            reader.close();
        } catch (IOException e) {
            System.out.println("Failed closing Input: " + e);
        }
    }

}
